﻿using Microsoft.AspNetCore.Mvc;
using SmartHotel.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace SmartHotel.VIPGrade
{
    [ApiExplorerSettings(GroupName = "v2")]
    public class SmartHotelAppVIPGradeService : ApplicationService, ISmartHotelAppVIPGradeService
    {
        private readonly IRepository<SmartHotel_Grade, int> _VIPRepository;
        public SmartHotelAppVIPGradeService(IRepository<SmartHotel_Grade, int> vIPRepository)
        {
            _VIPRepository = vIPRepository;
        }

        public async Task<ResultDto<CreateandUpdateGradeDto>> CreateGrade(CreateandUpdateGradeDto model)
        {
            var list = await _VIPRepository.InsertAsync(ObjectMapper.Map<CreateandUpdateGradeDto, SmartHotel_Grade>(model));
            return new ResultDto<CreateandUpdateGradeDto> { Code = Result.Success, Data = list ,Message="添加会员成功"};
        }

        public async Task<ResultDto<GradeListDto>> GetGrade()
        {
            var list = await _VIPRepository.GetQueryableAsync();
            return new ResultDto<GradeListDto> {Code=Result.Success,Data=list };
        }

        public async Task<ResultDto<CreateandUpdateGradeDto>> UpdateGrade(CreateandUpdateGradeDto model)
        {
            var list = await _VIPRepository.UpdateAsync(ObjectMapper.Map<CreateandUpdateGradeDto, SmartHotel_Grade>(model));
            return new ResultDto<CreateandUpdateGradeDto> { Code = Result.Success, Data = list, Message = "修改会员成功" };
        }
    }
}
